﻿using System;
using System.IO.IsolatedStorage;
using System.Net;
using System.Xml.Linq;

namespace _43Things
{
    public partial class Personal
    {
        private readonly IsolatedStorageSettings _userSetting = IsolatedStorageSettings.ApplicationSettings;

        private XElement ResultXml { get; set; }

        public Personal()
        {
            InitializeComponent();
            GetPersonEntries();
        }

        private string GetUsername()
        {
            return _userSetting["username"].ToString();
            //PageTitle.Text = Username;
        }
        private string GetPassword()
        {
            return _userSetting["password"].ToString();
        }

        private void GetPersonEntries()
        {
            var credentials = new NetworkCredential(GetUsername(), GetPassword());
            string url = string.Format("{0}{1}", "http://www.43things.com/service/get_persons_entries?api_key=545008@43rtF0IcpguS2&id=", GetUsername());
            var createWebRequestReturnSoap = new CreateWebRequestReturnSoap(url, credentials);
            ResultXml = createWebRequestReturnSoap.ResultXml;
            Read(ResultXml);
        }

        private void Read(XElement resultXml)
        {
            if (resultXml != null)
            {
                foreach (XElement element in resultXml.Elements())
                {
                    //element.Value;
                }
            }
        }
    }
}